home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------------------
- *
- * IPM MessageBoard AOCE Sample
- *
- * ©1992-1993 Apple Computer
- *
- -------------------------------------------------------------------------------------*/
- /*
- * events.c -- main event loop and basic event handling
- *
- * change history:
- *
- * SJF 2/12/93 1.0b1 udpate to AOCE beta seed
- * SJF 11/6/91 1.0d1 initial coding
- *
- */
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
- #ifndef __NOTIFICATION__
- #include <Notification.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
-
- #include "const.h"
- #include "mymenus.h"
- #include "globals.h"
- #include "utils.h"
- #include "commands.h"
- #include "statusdialog.h"
- #include "myipm.h"
-
- #include "myevents.h"
-
- /* main event loop */
-
- void MainLoop(void)
- {
- EventRecord ev;
- Boolean gotEvent;
-
- while (!gDone) {
- if (gHasWaitNextEvent)
- gotEvent = WaitNextEvent(everyEvent,&ev,SleepTime(),nil);
- else {
- gotEvent = GetNextEvent(everyEvent,&ev);
- SystemTask();
- }
-
- ProcessEvent(&ev);
- }
- }
-
-
- /* calculate how long to "wait" */
-
- long SleepTime(void)
- {
- if (gInBackground)
- return kSleepBackground;
- else
- return kSleepForeground;
- }
-
-
- /* idle time processing */
-
- void HandleIdle(void)
- {
- MyQElemPtr qBlock;
-
- while (qBlock = GetCompletedQBlock()) {
- ProcessNotification(qBlock);
- }
- }
-
-
- /* process an event gotten by MainLoop() */
-
- void ProcessEvent(EventRecord *ev)
- {
- if (HandleDialogEvents(ev))
- return;
-
- switch (ev->what) {
- case mouseDown:
- HandleMouseDowns(ev);
- break;
- case keyDown:
- case autoKey:
- HandleKeyDowns(ev);
- break;
- case updateEvt:
- HandleUpdates((WindowPtr)ev->message);
- break;
- case activateEvt:
- HandleActivates(ev);
- break;
- case osEvt:
- HandleSREvt(ev->message);
- break;
- case nullEvent:
- HandleIdle();
- break;
- }
- }
-
-
- /* Handles suspend and resume events */
-
- void HandleSREvt(long message)
- {
- extern NMRec *gNotify;
- extern Boolean gInBackground;
- unsigned long whatMessage;
-
- whatMessage = message >> 24;
-
- if (whatMessage==suspendResumeMessage) {
- if ((message & 1) != 0) {
- gInBackground = false;
- SetCursor(&qd.arrow);
- if (FrontWindow()) {
- HiliteWindow(FrontWindow(),true);
- DoActivate(FrontWindow(),true);
- }
- }
- else if (FrontWindow()) {
- gInBackground = true;
- HiliteWindow(FrontWindow(),false);
- DoDeActivate(FrontWindow(),true);
- }
- }
- else if ((whatMessage&mouseMovedMessage)==mouseMovedMessage)
- ;
- }
-
-
- /* Handles activate and deactivate events for a window */
-
- void HandleActivates(EventRecord *ev)
- {
- if ((ev->modifiers & activeFlag) != 0) {
- DoActivate((WindowPtr)ev->message,((ev->modifiers & 0x0002) != 0));
- }
- else {
- DoDeActivate((WindowPtr)ev->message,((ev->modifiers & 0x0002) != 0));
- }
- }
-
-
- /* Handles activate events for a window */
-
- void DoActivate(WindowPtr window,Boolean chFlag)
- {
- #pragma unused (window,chFlag)
- }
-
-
- /* Handles deactivate events for a window */
-
- void DoDeActivate(WindowPtr window,Boolean chFlag)
- {
- #pragma unused (window,chFlag)
- }
-
-
- /* handles update events for a window */
-
- void HandleUpdates(WindowPtr window)
- {
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(window);
- BeginUpdate(window);
- EraseRect(&window->portRect);
- EndUpdate(window);
- SetPort(savePort);
- }
-
-
- /* handles program keydowns */
-
- void HandleKeyDowns(EventRecord *ev)
- {
- short theChar;
-
- theChar = ev->message & charCodeMask;
- if ((ev->modifiers & cmdKey) != 0)
- DoMenuCommand(MenuKey(theChar));
- }
-
-
- /* handles mouse down events for a window */
-
- void HandleMouseDowns(EventRecord *ev)
- {
- WindowPtr window;
- short part;
- Rect limit;
-
- SetRect(&limit,-32000,-32000,32000,32000);
-
- part = FindWindow(ev->where,&window);
-
- switch (FindWindow(ev->where,&window)) {
- case inDrag:
- DragWindow(window,ev->where,&limit);
- break;
- case inGoAway:
- if (TrackGoAway(window,ev->where))
- gDone = true;
- break;
- case inMenuBar:
- DoMenuCommand(MenuSelect(ev->where));
- break;
- case inSysWindow:
- SystemClick(ev,window);
- break;
- }
- }
-
-
- /* handles menu commands */
-
- void DoMenuCommand(long mResult)
- {
- short selItem,selMenu,temp;
- Str255 name;
- GrafPtr tempPort;
- MenuHandle theMenu;
-
- selItem = LoWord(mResult);
- selMenu = HiWord(mResult);
- switch (selMenu) {
- case kAppleMenu:
- if (selItem>2) {
- GetPort(&tempPort);
- SetCursor(&qd.arrow);
- theMenu = GetMHandle(kAppleMenu);
- GetItem(theMenu,selItem,name);
- temp = OpenDeskAcc((ConstStr255Param)&name);
- SetPort(tempPort);
- }
- else CommAbout();
- break;
- case kFileMenu:
- switch (selItem) {
- case kQuitItem:
- gDone = true;
- break;
- }
- break;
- case kEditMenu:
- SystemEdit(selItem-1);
- break;
- }
- HiliteMenu(0);
- }
-
-
- void ExitProgram(void)
- {
- CloseMainDialog();
- CloseIPM();
- }
-